local sk__huiqu = fk.CreateSkill {

  name = "sk__huiqu",

  tags = {},

}



sk__huiqu:addEffect(fk.EventPhaseStart, {
  name = "sk__huiqu",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__huiqu.name) and not player:isKongcheng() and
    player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, sk__huiqu.name, true, ".", "#sk__huiqu-invoke", true)
    if #card > 0 then
      event:setCostData(self, card)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), sk__huiqu.name, player, player)
    if player.dead then return end
    local judge = {
      who = target,
      reason = sk__huiqu.name,
      pattern = ".",
    }
    room:judge(judge)
    if player.dead then return end
    if judge.card.color == Card.Red then
      local targets = room:askForChooseToMoveCardInBoard(player, "#sk__huiqu-move", sk__huiqu.name, false, nil)
      if #targets ~= 0 then
        targets = table.map(targets, Util.Id2PlayerMapper)
        room:askForMoveCardInBoard(player, targets[1], targets[2], sk__huiqu.name)
      end
    elseif judge.card.color == Card.Black then
      local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#sk__huiqu-choose", sk__huiqu.name, false)
      to = room:getPlayerById(to[1])
      room:damage {
        from = player,
        to = to,
        damage = 1,
        skillName = sk__huiqu.name,
      }
      if not to.dead then
        to:drawCards(1, sk__huiqu.name)
      end
    end
  end,
})

return sk__huiqu
